const express = require("express");
const path = require('path')
const chat = require("./chat/chat");
const api = require("./router/api");
const cors = require("cors");
const { createServer } = require("node:http");
const { ExpressPeerServer } = require("peer");

const app = express();
app.use(cors());
app.use(express.json()); // 用于解析application/json类型的数据
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use("/api", api);
app.use("/", express.static(path.join(__dirname, "public")));
const server = createServer(app);
const peerServer = ExpressPeerServer(server, {
  proxied: true,
  debug: true,
  path: "/",
});
app.use(peerServer);
chat.getSocket(server);
server.listen(6060, () => {
  console.log("服务器已开启");
});
